{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pandas\n",
    "import numpy as numpy\n",
    "\n",
    "import matplotlib.pyplot as matplot\n",
    "import seaborn as seaborn\n",
    "train = pandas.read_csv('Train.csv')#读入训练数据\n",
    "test = pandas.read_csv('Test.csv')#读入测试数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 87020 entries, 0 to 87019\n",
      "Data columns (total 26 columns):\n",
      "ID                       87020 non-null object\n",
      "Gender                   87020 non-null object\n",
      "City                     86017 non-null object\n",
      "Monthly_Income           87020 non-null int64\n",
      "DOB                      87020 non-null object\n",
      "Lead_Creation_Date       87020 non-null object\n",
      "Loan_Amount_Applied      86949 non-null float64\n",
      "Loan_Tenure_Applied      86949 non-null float64\n",
      "Existing_EMI             86949 non-null float64\n",
      "Employer_Name            86949 non-null object\n",
      "Salary_Account           75256 non-null object\n",
      "Mobile_Verified          87020 non-null object\n",
      "Var5                     87020 non-null int64\n",
      "Var1                     87020 non-null object\n",
      "Loan_Amount_Submitted    52407 non-null float64\n",
      "Loan_Tenure_Submitted    52407 non-null float64\n",
      "Interest_Rate            27726 non-null float64\n",
      "Processing_Fee           27420 non-null float64\n",
      "EMI_Loan_Submitted       27726 non-null float64\n",
      "Filled_Form              87020 non-null object\n",
      "Device_Type              87020 non-null object\n",
      "Var2                     87020 non-null object\n",
      "Source                   87020 non-null object\n",
      "Var4                     87020 non-null int64\n",
      "LoggedIn                 87020 non-null int64\n",
      "Disbursed                87020 non-null int64\n",
      "dtypes: float64(8), int64(5), object(13)\n",
      "memory usage: 17.3+ MB\n",
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 37717 entries, 0 to 37716\n",
      "Data columns (total 24 columns):\n",
      "ID                       37717 non-null object\n",
      "Gender                   37717 non-null object\n",
      "City                     37319 non-null object\n",
      "Monthly_Income           37717 non-null int64\n",
      "DOB                      37717 non-null object\n",
      "Lead_Creation_Date       37717 non-null object\n",
      "Loan_Amount_Applied      37677 non-null float64\n",
      "Loan_Tenure_Applied      37677 non-null float64\n",
      "Existing_EMI             37677 non-null float64\n",
      "Employer_Name            37675 non-null object\n",
      "Salary_Account           32680 non-null object\n",
      "Mobile_Verified          37717 non-null object\n",
      "Var5                     37717 non-null int64\n",
      "Var1                     37717 non-null object\n",
      "Loan_Amount_Submitted    22795 non-null float64\n",
      "Loan_Tenure_Submitted    22795 non-null float64\n",
      "Interest_Rate            12110 non-null float64\n",
      "Processing_Fee           11971 non-null float64\n",
      "EMI_Loan_Submitted       12110 non-null float64\n",
      "Filled_Form              37717 non-null object\n",
      "Device_Type              37717 non-null object\n",
      "Var2                     37717 non-null object\n",
      "Source                   37717 non-null object\n",
      "Var4                     37717 non-null int64\n",
      "dtypes: float64(8), int64(3), object(13)\n",
      "memory usage: 6.9+ MB\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(None, None)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.info(),test.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Monthly_Income</th>\n",
       "      <th>Loan_Amount_Applied</th>\n",
       "      <th>Loan_Tenure_Applied</th>\n",
       "      <th>Existing_EMI</th>\n",
       "      <th>Var5</th>\n",
       "      <th>Loan_Amount_Submitted</th>\n",
       "      <th>Loan_Tenure_Submitted</th>\n",
       "      <th>Interest_Rate</th>\n",
       "      <th>Processing_Fee</th>\n",
       "      <th>EMI_Loan_Submitted</th>\n",
       "      <th>Var4</th>\n",
       "      <th>LoggedIn</th>\n",
       "      <th>Disbursed</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>1.247370e+05</td>\n",
       "      <td>1.246260e+05</td>\n",
       "      <td>124626.000000</td>\n",
       "      <td>1.246260e+05</td>\n",
       "      <td>124737.000000</td>\n",
       "      <td>7.520200e+04</td>\n",
       "      <td>75202.000000</td>\n",
       "      <td>39836.000000</td>\n",
       "      <td>39391.000000</td>\n",
       "      <td>39836.000000</td>\n",
       "      <td>124737.000000</td>\n",
       "      <td>87020.000000</td>\n",
       "      <td>87020.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>5.309073e+04</td>\n",
       "      <td>2.299901e+05</td>\n",
       "      <td>2.138197</td>\n",
       "      <td>3.636342e+03</td>\n",
       "      <td>4.964774</td>\n",
       "      <td>3.949007e+05</td>\n",
       "      <td>3.895535</td>\n",
       "      <td>19.217054</td>\n",
       "      <td>5124.417684</td>\n",
       "      <td>10982.549579</td>\n",
       "      <td>2.950560</td>\n",
       "      <td>0.029350</td>\n",
       "      <td>0.014629</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>1.823394e+06</td>\n",
       "      <td>3.541301e+05</td>\n",
       "      <td>2.015767</td>\n",
       "      <td>3.369124e+04</td>\n",
       "      <td>5.669784</td>\n",
       "      <td>3.074236e+05</td>\n",
       "      <td>1.161151</td>\n",
       "      <td>5.846375</td>\n",
       "      <td>4730.698299</td>\n",
       "      <td>7466.525227</td>\n",
       "      <td>1.695261</td>\n",
       "      <td>0.168785</td>\n",
       "      <td>0.120062</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>5.000000e+04</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>11.990000</td>\n",
       "      <td>200.000000</td>\n",
       "      <td>1176.410000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>1.650000e+04</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.000000e+05</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>15.150000</td>\n",
       "      <td>2000.000000</td>\n",
       "      <td>6390.380000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>2.500000e+04</td>\n",
       "      <td>1.000000e+05</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>3.000000e+05</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>18.000000</td>\n",
       "      <td>3900.000000</td>\n",
       "      <td>9409.230000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>4.000000e+04</td>\n",
       "      <td>3.000000e+05</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>3.500000e+03</td>\n",
       "      <td>11.000000</td>\n",
       "      <td>5.000000e+05</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>6250.000000</td>\n",
       "      <td>12909.270000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>4.445544e+08</td>\n",
       "      <td>1.500000e+07</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>1.000000e+07</td>\n",
       "      <td>18.000000</td>\n",
       "      <td>3.000000e+06</td>\n",
       "      <td>6.000000</td>\n",
       "      <td>37.000000</td>\n",
       "      <td>50000.000000</td>\n",
       "      <td>144748.280000</td>\n",
       "      <td>7.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       Monthly_Income  Loan_Amount_Applied  Loan_Tenure_Applied  Existing_EMI  \\\n",
       "count    1.247370e+05         1.246260e+05        124626.000000  1.246260e+05   \n",
       "mean     5.309073e+04         2.299901e+05             2.138197  3.636342e+03   \n",
       "std      1.823394e+06         3.541301e+05             2.015767  3.369124e+04   \n",
       "min      0.000000e+00         0.000000e+00             0.000000  0.000000e+00   \n",
       "25%      1.650000e+04         0.000000e+00             0.000000  0.000000e+00   \n",
       "50%      2.500000e+04         1.000000e+05             2.000000  0.000000e+00   \n",
       "75%      4.000000e+04         3.000000e+05             4.000000  3.500000e+03   \n",
       "max      4.445544e+08         1.500000e+07            10.000000  1.000000e+07   \n",
       "\n",
       "                Var5  Loan_Amount_Submitted  Loan_Tenure_Submitted  \\\n",
       "count  124737.000000           7.520200e+04           75202.000000   \n",
       "mean        4.964774           3.949007e+05               3.895535   \n",
       "std         5.669784           3.074236e+05               1.161151   \n",
       "min         0.000000           5.000000e+04               1.000000   \n",
       "25%         0.000000           2.000000e+05               3.000000   \n",
       "50%         2.000000           3.000000e+05               4.000000   \n",
       "75%        11.000000           5.000000e+05               5.000000   \n",
       "max        18.000000           3.000000e+06               6.000000   \n",
       "\n",
       "       Interest_Rate  Processing_Fee  EMI_Loan_Submitted           Var4  \\\n",
       "count   39836.000000    39391.000000        39836.000000  124737.000000   \n",
       "mean       19.217054     5124.417684        10982.549579       2.950560   \n",
       "std         5.846375     4730.698299         7466.525227       1.695261   \n",
       "min        11.990000      200.000000         1176.410000       0.000000   \n",
       "25%        15.150000     2000.000000         6390.380000       1.000000   \n",
       "50%        18.000000     3900.000000         9409.230000       3.000000   \n",
       "75%        20.000000     6250.000000        12909.270000       5.000000   \n",
       "max        37.000000    50000.000000       144748.280000       7.000000   \n",
       "\n",
       "           LoggedIn     Disbursed  \n",
       "count  87020.000000  87020.000000  \n",
       "mean       0.029350      0.014629  \n",
       "std        0.168785      0.120062  \n",
       "min        0.000000      0.000000  \n",
       "25%        0.000000      0.000000  \n",
       "50%        0.000000      0.000000  \n",
       "75%        0.000000      0.000000  \n",
       "max        1.000000      1.000000  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.head(5),test.head(5)\n",
    "train['source']= 'train'\n",
    "test['source'] = 'test'\n",
    "data = pandas.concat([train, test],ignore_index=True,sort=False)\n",
    "data.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZUAAAEKCAYAAADaa8itAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvIxREBQAAFeFJREFUeJzt3X2wZVV95vHvA4i0CgLaWKaBNMaOSnR8awmaTIyg2OgEkJIEyxFGmcFkwJdJdIQkJVFEJRGMJL6ECgRwDIgEtFWUQQScOIo0L4oNUnQwQg8EWkHkZYBp+M0fZ1043X1fdt/ep28f7/dTdeqevc7a+/wOBTy19tp77VQVkiT1Yau5LkCS9MvDUJEk9cZQkST1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qjSMVSVJvDBVJUm8MFUlSbwwVSVJvDBVJUm8MFamjJI8kuTbJyiTfT/LHSbZqny1Ncso0+/5ukq9svmo3+P6/SPKeufp+zR9j/+RHaTP6v1X1IoAkuwD/CDwVOK6qVgArRvXFSbZp9wdJWzRHKtIsVNWdwJHA0Rl4bCSS5JVtRHNtkmuSbN922yHJBUmuT/KZoVHOfRPHTfLGJGe092ckOTnJpcCJUx03yXuTXJnkB0k+MHSsP2vPvPkG8JzN8c9FcqQizVJV3dyCYZf1PnoPcFRVfTvJU4AHW/teDJ4/8xPg68DBwHkzfM2vA6+uqkeSfHn94ybZD1jSjh1geZLfAe5nsHzOixn8d341cNWm/WJpZo5UpE0z2YrN3wZOTvJOYMeh01bfa8+geQQ4G/jtDsf/Qus/1XH3a69rGATHcxmEzL8HLqiqB6rqF7g2mzYTQ0WapSTPAh4B7hxur6qPAv8ZWAB8N8lzJz5a7xA1Sft26/W5f4bjBvhIVb2ovZ5dVadN8X3SyBkq0iwkWQh8BvjbWm8BvSS/VlXXVdWJDCbvJ0Jlr7ay81bAHwD/3NrvSPK81v6Gab5zsuNeBLytnQ4jyaJ2EcG3gDckWdDmXn6vr98uTcc5Fam7BUmuBZ4ArAU+C5w8Sb93J3kVg1HM9cDXgJczWDn3o8ALGPxP/4LW/xjgKwyepvlD4ClTfP8Gx62qh5I8D/hOEoD7gP9YVVcn+TxwLYM5nP+1KT9c6spViiVJvfH0lySpN4aKJKk3hookqTeGiiSpN4aKJKk3hookqTeGiiSpN4aKJKk3/x++6iyfp4e+ywAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "seaborn.countplot(train['Disbursed']);\n",
    "matplot.xlabel('Disbursed');\n",
    "matplot.ylabel('Number of occurrences');"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "ID                           0\n",
       "Gender                       0\n",
       "City                      1401\n",
       "Monthly_Income               0\n",
       "DOB                          0\n",
       "Lead_Creation_Date           0\n",
       "Loan_Amount_Applied        111\n",
       "Loan_Tenure_Applied        111\n",
       "Existing_EMI               111\n",
       "Employer_Name              113\n",
       "Salary_Account           16801\n",
       "Mobile_Verified              0\n",
       "Var5                         0\n",
       "Var1                         0\n",
       "Loan_Amount_Submitted    49535\n",
       "Loan_Tenure_Submitted    49535\n",
       "Interest_Rate            84901\n",
       "Processing_Fee           85346\n",
       "EMI_Loan_Submitted       84901\n",
       "Filled_Form                  0\n",
       "Device_Type                  0\n",
       "Var2                         0\n",
       "Source                       0\n",
       "Var4                         0\n",
       "LoggedIn                 37717\n",
       "Disbursed                37717\n",
       "source                       0\n",
       "dtype: int64"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.isnull().sum()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "可以看到这里都有很多空值。LightGBM可以处理空值,暂时不对控制进行处理，对于确实比较多的建立一个是否为空的变量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "data['EMI_Loan_Submitted_Missing'] = data['EMI_Loan_Submitted'].apply(lambda x: 1 if pandas.isnull(x) else 0)\n",
    "data['Interest_Rate_Missing'] = data['Interest_Rate'].apply(lambda x: 1 if pandas.isnull(x) else 0)\n",
    "data['Processing_Fee_Missing'] = data['Processing_Fee'].apply(lambda x: 1 if pandas.isnull(x) else 0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "需要进行特征编码"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "类别行变量出现频次："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Gender属性有2的不同取值，各取值及其出现的次数\n",
      "\n",
      "Male      71398\n",
      "Female    53339\n",
      "Name: Gender, dtype: int64\n",
      "\n",
      "City属性有698的不同取值，各取值及其出现的次数\n",
      "\n",
      "Delhi                  17936\n",
      "Bengaluru              15522\n",
      "Mumbai                 15425\n",
      "Hyderabad              10410\n",
      "Chennai                 9895\n",
      "Pune                    7427\n",
      "Kolkata                 4282\n",
      "Ahmedabad               2528\n",
      "Jaipur                  1892\n",
      "Gurgaon                 1743\n",
      "Coimbatore              1659\n",
      "Thane                   1306\n",
      "Chandigarh              1266\n",
      "Surat                   1149\n",
      "Visakhapatnam           1080\n",
      "Indore                  1051\n",
      "Vadodara                 893\n",
      "Nagpur                   879\n",
      "Lucknow                  813\n",
      "Ghaziabad                795\n",
      "Bhopal                   735\n",
      "Kochi                    692\n",
      "Patna                    675\n",
      "Faridabad                651\n",
      "Noida                    549\n",
      "Madurai                  534\n",
      "Gautam Buddha Nagar      485\n",
      "Dehradun                 444\n",
      "Raipur                   430\n",
      "Bhubaneswar              407\n",
      "                       ...  \n",
      "Sawai Madhopur             1\n",
      "SOMNATH JUNAGADHA          1\n",
      "Chinnamiram                1\n",
      "Bandipore                  1\n",
      "CHIKHLI (GUJ.)             1\n",
      "Raisen                     1\n",
      "Dhalai                     1\n",
      "Rudraprayag                1\n",
      "Panna                      1\n",
      "UDWADA                     1\n",
      "Siruguppa                  1\n",
      "Kullu                      1\n",
      "Seoni                      1\n",
      "Umaria                     1\n",
      "Mainpuri                   1\n",
      "LUNAWADA                   1\n",
      "Champhai                   1\n",
      "Malkangiri                 1\n",
      "Hazaribagh                 1\n",
      "Tawang                     1\n",
      "Champawat                  1\n",
      "DHANDHUKA                  1\n",
      "Ramanagara                 1\n",
      "Magadh                     1\n",
      "Sheikhpura                 1\n",
      "Lohit                      1\n",
      "Bageshwar                  1\n",
      "Latehar                    1\n",
      "Pulwama                    1\n",
      "SAYAN                      1\n",
      "Name: City, Length: 723, dtype: int64\n",
      "\n",
      "Employer_Name属性有43568的不同取值，各取值及其出现的次数\n",
      "\n",
      "0                                               6900\n",
      "TATA CONSULTANCY SERVICES LTD (TCS)              754\n",
      "COGNIZANT TECHNOLOGY SOLUTIONS INDIA PVT LTD     558\n",
      "ACCENTURE SERVICES PVT LTD                       476\n",
      "GOOGLE                                           408\n",
      "ICICI BANK LTD                                   337\n",
      "HCL TECHNOLOGIES LTD                             337\n",
      "IBM CORPORATION                                  265\n",
      "INDIAN AIR FORCE                                 258\n",
      "INFOSYS TECHNOLOGIES                             257\n",
      "INDIAN ARMY                                      243\n",
      "GENPACT                                          240\n",
      "WIPRO TECHNOLOGIES                               235\n",
      "TYPE SLOWLY FOR AUTO FILL                        219\n",
      "IKYA HUMAN CAPITAL SOLUTIONS LTD                 204\n",
      "ARMY                                             203\n",
      "INDIAN RAILWAY                                   201\n",
      "HDFC BANK LTD                                    201\n",
      "STATE GOVERNMENT                                 199\n",
      "WIPRO BPO                                        186\n",
      "INDIAN NAVY                                      183\n",
      "CONVERGYS INDIA SERVICES PVT LTD                 165\n",
      "OTHERS                                           159\n",
      "TECH MAHINDRA LTD                                158\n",
      "IBM GLOBAL SERVICES INDIA LTD                    158\n",
      "CONCENTRIX DAKSH SERVICES INDIA PVT LTD          154\n",
      "CAPGEMINI INDIA PVT LTD                          152\n",
      "SERCO BPO PVT LTD                                149\n",
      "SUTHERLAND GLOBAL SERVICES PVT LTD               141\n",
      "ADECCO INDIA PVT LTD                             140\n",
      "                                                ... \n",
      "VENKATESHARA RESEACH AND BREEDING                  1\n",
      "LAKHAN LAL SINHA                                   1\n",
      "HAJEE A P BAVA COM CONSTRUCT P LTD                 1\n",
      "SUPER HITER ENTERPRISE                             1\n",
      "PRATIK                                             1\n",
      "RAMANJANEYULU G                                    1\n",
      "MEGA BYTE CORPORATION                              1\n",
      "VEDANJAY POWER PRIVATE LIMITED                     1\n",
      "HOTEL PRIDE AMBER VILAS                            1\n",
      "ASC CENTRE AND COLLEGE                             1\n",
      "VEEPURI. SUJATHA                                   1\n",
      "RICO ALUMINIUM N FERROUS AUTO COM L                1\n",
      "ESS TEE EXPORT                                     1\n",
      "UHGIT                                              1\n",
      "AMBEST PRINTS PVT LTD                              1\n",
      "NNK                                                1\n",
      "SJR PRIME CORPORATION PVT LTD                      1\n",
      "BAJAJ ALLIANZ GIC                                  1\n",
      "SKY GROUP CONSULTING                               1\n",
      "A. A. NAYAK CONSTRUCTIONS PVT. LTD.                1\n",
      "RAJUU                                              1\n",
      "HARSHAD PANCHAL                                    1\n",
      "SHREE BALAJI CONSULTANCY                           1\n",
      "HILTON GARDEN INN                                  1\n",
      "VISHAL SHIPPING AGENCIES PVT LTD                   1\n",
      "CHHATTU SHIKARI                                    1\n",
      "MANZOOR ALI                                        1\n",
      "PARIKH AGENCY                                      1\n",
      "SRINIVAS PRADHAN                                   1\n",
      "AAKRITI FURNISHERS PVT LTD                         1\n",
      "Name: Employer_Name, Length: 57193, dtype: int64\n",
      "\n",
      "Salary_Account属性有58的不同取值，各取值及其出现的次数\n",
      "\n",
      "HDFC Bank                                          25180\n",
      "ICICI Bank                                         19547\n",
      "State Bank of India                                17110\n",
      "Axis Bank                                          12590\n",
      "Citibank                                            3398\n",
      "Kotak Bank                                          2955\n",
      "IDBI Bank                                           2213\n",
      "Punjab National Bank                                1747\n",
      "Bank of India                                       1713\n",
      "Bank of Baroda                                      1675\n",
      "Standard Chartered Bank                             1434\n",
      "Canara Bank                                         1385\n",
      "Union Bank of India                                 1330\n",
      "Yes Bank                                            1120\n",
      "ING Vysya                                            996\n",
      "Corporation bank                                     948\n",
      "Indian Overseas Bank                                 901\n",
      "State Bank of Hyderabad                              854\n",
      "Indian Bank                                          773\n",
      "Oriental Bank of Commerce                            761\n",
      "IndusInd Bank                                        711\n",
      "Andhra Bank                                          706\n",
      "Central Bank of India                                648\n",
      "Syndicate Bank                                       614\n",
      "Bank of Maharasthra                                  576\n",
      "HSBC                                                 474\n",
      "State Bank of Bikaner & Jaipur                       448\n",
      "Karur Vysya Bank                                     435\n",
      "State Bank of Mysore                                 385\n",
      "Federal Bank                                         377\n",
      "Vijaya Bank                                          354\n",
      "Allahabad Bank                                       345\n",
      "UCO Bank                                             344\n",
      "State Bank of Travancore                             333\n",
      "Karnataka Bank                                       279\n",
      "United Bank of India                                 276\n",
      "Dena Bank                                            268\n",
      "Saraswat Bank                                        265\n",
      "State Bank of Patiala                                263\n",
      "South Indian Bank                                    223\n",
      "Deutsche Bank                                        176\n",
      "Abhyuday Co-op Bank Ltd                              161\n",
      "The Ratnakar Bank Ltd                                113\n",
      "Tamil Nadu Mercantile Bank                           103\n",
      "Punjab & Sind bank                                    84\n",
      "J&K Bank                                              78\n",
      "Lakshmi Vilas bank                                    69\n",
      "Dhanalakshmi Bank Ltd                                 66\n",
      "State Bank of Indore                                  32\n",
      "Catholic Syrian Bank                                  27\n",
      "India Bulls                                           21\n",
      "B N P Paribas                                         15\n",
      "Firstrand Bank Limited                                11\n",
      "GIC Housing Finance Ltd                               10\n",
      "Bank of Rajasthan                                      8\n",
      "Kerala Gramin Bank                                     4\n",
      "Industrial And Commercial Bank Of China Limited        3\n",
      "Ahmedabad Mercantile Cooperative Bank                  1\n",
      "Name: Salary_Account, dtype: int64\n",
      "\n",
      "Mobile_Verified属性有2的不同取值，各取值及其出现的次数\n",
      "\n",
      "Y    80928\n",
      "N    43809\n",
      "Name: Mobile_Verified, dtype: int64\n",
      "\n",
      "Var1属性有19的不同取值，各取值及其出现的次数\n",
      "\n",
      "HBXX    84901\n",
      "HBXC    12952\n",
      "HBXB     6502\n",
      "HAXA     4214\n",
      "HBXA     3042\n",
      "HAXB     2879\n",
      "HBXD     2818\n",
      "HAXC     2171\n",
      "HBXH     1387\n",
      "HCXF      990\n",
      "HAYT      710\n",
      "HAVC      570\n",
      "HAXM      386\n",
      "HCXD      348\n",
      "HCYS      318\n",
      "HVYS      252\n",
      "HAZD      161\n",
      "HCXG      114\n",
      "HAXF       22\n",
      "Name: Var1, dtype: int64\n",
      "\n",
      "Filled_Form属性有2的不同取值，各取值及其出现的次数\n",
      "\n",
      "N    96740\n",
      "Y    27997\n",
      "Name: Filled_Form, dtype: int64\n",
      "\n",
      "Device_Type属性有2的不同取值，各取值及其出现的次数\n",
      "\n",
      "Web-browser    92105\n",
      "Mobile         32632\n",
      "Name: Device_Type, dtype: int64\n",
      "\n",
      "Var2属性有7的不同取值，各取值及其出现的次数\n",
      "\n",
      "B    53481\n",
      "G    47338\n",
      "C    20366\n",
      "E     1855\n",
      "D      918\n",
      "F      770\n",
      "A        9\n",
      "Name: Var2, dtype: int64\n",
      "\n",
      "Source属性有30的不同取值，各取值及其出现的次数\n",
      "\n",
      "S122    55249\n",
      "S133    42900\n",
      "S159     7999\n",
      "S143     6140\n",
      "S127     2804\n",
      "S137     2450\n",
      "S134     1900\n",
      "S161     1109\n",
      "S151     1018\n",
      "S157      929\n",
      "S153      705\n",
      "S144      447\n",
      "S156      432\n",
      "S158      294\n",
      "S123      112\n",
      "S141       83\n",
      "S162       60\n",
      "S124       43\n",
      "S150       19\n",
      "S160       11\n",
      "S136        5\n",
      "S138        5\n",
      "S155        5\n",
      "S139        4\n",
      "S129        4\n",
      "S135        2\n",
      "S131        1\n",
      "S130        1\n",
      "S132        1\n",
      "S125        1\n",
      "S140        1\n",
      "S142        1\n",
      "S126        1\n",
      "S154        1\n",
      "Name: Source, dtype: int64\n",
      "\n",
      "Var4属性有8的不同取值，各取值及其出现的次数\n",
      "\n",
      "3    36280\n",
      "1    34316\n",
      "5    29092\n",
      "4     9411\n",
      "2     8481\n",
      "0     3564\n",
      "7     3264\n",
      "6      329\n",
      "Name: Var4, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "cat_features = ['Gender','City','Employer_Name','Salary_Account','Mobile_Verified','Var1','Filled_Form','Device_Type','Var2','Source','Var4']\n",
    "for col in cat_features:\n",
    "    num_vlaules = len(train[col].unique())\n",
    "    print ('\\n%s属性有%d的不同取值，各取值及其出现的次数\\n'% (col,num_vlaules) )\n",
    "    print data[col].value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 日期型转换："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    40\n",
       "1    33\n",
       "2    37\n",
       "3    31\n",
       "4    34\n",
       "Name: Age, dtype: int64"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "data['Age'] =datetime.now().year- pandas.to_datetime(data['DOB']).dt.year"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "data.drop(['DOB'],axis=1,inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    3\n",
       "1    3\n",
       "2    3\n",
       "3    3\n",
       "4    3\n",
       "Name: Lead_Creation_Year, dtype: int64"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['Lead_Creation_Year'] =datetime.now().year- pandas.to_datetime(data['Lead_Creation_Date']).dt.year\n",
    "data.drop(['Lead_Creation_Date'],axis=1,inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ID</th>\n",
       "      <th>Gender</th>\n",
       "      <th>City</th>\n",
       "      <th>Monthly_Income</th>\n",
       "      <th>Loan_Amount_Applied</th>\n",
       "      <th>Loan_Tenure_Applied</th>\n",
       "      <th>Existing_EMI</th>\n",
       "      <th>Employer_Name</th>\n",
       "      <th>Salary_Account</th>\n",
       "      <th>Mobile_Verified</th>\n",
       "      <th>...</th>\n",
       "      <th>Source</th>\n",
       "      <th>Var4</th>\n",
       "      <th>LoggedIn</th>\n",
       "      <th>Disbursed</th>\n",
       "      <th>source</th>\n",
       "      <th>EMI_Loan_Submitted_Missing</th>\n",
       "      <th>Interest_Rate_Missing</th>\n",
       "      <th>Processing_Fee_Missing</th>\n",
       "      <th>Age</th>\n",
       "      <th>Lead_Creation_Year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>ID000002C20</td>\n",
       "      <td>Female</td>\n",
       "      <td>Delhi</td>\n",
       "      <td>20000</td>\n",
       "      <td>300000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>CYBOSOL</td>\n",
       "      <td>HDFC Bank</td>\n",
       "      <td>N</td>\n",
       "      <td>...</td>\n",
       "      <td>S122</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>train</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>40</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ID000004E40</td>\n",
       "      <td>Male</td>\n",
       "      <td>Mumbai</td>\n",
       "      <td>35000</td>\n",
       "      <td>200000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>TATA CONSULTANCY SERVICES LTD (TCS)</td>\n",
       "      <td>ICICI Bank</td>\n",
       "      <td>Y</td>\n",
       "      <td>...</td>\n",
       "      <td>S122</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>train</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>33</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ID000007H20</td>\n",
       "      <td>Male</td>\n",
       "      <td>Panchkula</td>\n",
       "      <td>22500</td>\n",
       "      <td>600000.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>ALCHEMIST HOSPITALS LTD</td>\n",
       "      <td>State Bank of India</td>\n",
       "      <td>Y</td>\n",
       "      <td>...</td>\n",
       "      <td>S143</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>train</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>37</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>ID000008I30</td>\n",
       "      <td>Male</td>\n",
       "      <td>Saharsa</td>\n",
       "      <td>35000</td>\n",
       "      <td>1000000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>BIHAR GOVERNMENT</td>\n",
       "      <td>State Bank of India</td>\n",
       "      <td>Y</td>\n",
       "      <td>...</td>\n",
       "      <td>S143</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>train</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>31</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ID000009J40</td>\n",
       "      <td>Male</td>\n",
       "      <td>Bengaluru</td>\n",
       "      <td>100000</td>\n",
       "      <td>500000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>25000.0</td>\n",
       "      <td>GLOBAL EDGE SOFTWARE</td>\n",
       "      <td>HDFC Bank</td>\n",
       "      <td>Y</td>\n",
       "      <td>...</td>\n",
       "      <td>S134</td>\n",
       "      <td>3</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>train</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>34</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 30 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            ID  Gender       City  Monthly_Income  Loan_Amount_Applied  \\\n",
       "0  ID000002C20  Female      Delhi           20000             300000.0   \n",
       "1  ID000004E40    Male     Mumbai           35000             200000.0   \n",
       "2  ID000007H20    Male  Panchkula           22500             600000.0   \n",
       "3  ID000008I30    Male    Saharsa           35000            1000000.0   \n",
       "4  ID000009J40    Male  Bengaluru          100000             500000.0   \n",
       "\n",
       "   Loan_Tenure_Applied  Existing_EMI                        Employer_Name  \\\n",
       "0                  5.0           0.0                              CYBOSOL   \n",
       "1                  2.0           0.0  TATA CONSULTANCY SERVICES LTD (TCS)   \n",
       "2                  4.0           0.0              ALCHEMIST HOSPITALS LTD   \n",
       "3                  5.0           0.0                     BIHAR GOVERNMENT   \n",
       "4                  2.0       25000.0                 GLOBAL EDGE SOFTWARE   \n",
       "\n",
       "        Salary_Account Mobile_Verified        ...          Source Var4  \\\n",
       "0            HDFC Bank               N        ...            S122    1   \n",
       "1           ICICI Bank               Y        ...            S122    3   \n",
       "2  State Bank of India               Y        ...            S143    1   \n",
       "3  State Bank of India               Y        ...            S143    3   \n",
       "4            HDFC Bank               Y        ...            S134    3   \n",
       "\n",
       "   LoggedIn  Disbursed  source  EMI_Loan_Submitted_Missing  \\\n",
       "0       0.0        0.0   train                           1   \n",
       "1       0.0        0.0   train                           0   \n",
       "2       0.0        0.0   train                           1   \n",
       "3       0.0        0.0   train                           1   \n",
       "4       1.0        0.0   train                           1   \n",
       "\n",
       "   Interest_Rate_Missing Processing_Fee_Missing Age Lead_Creation_Year  \n",
       "0                      1                      1  40                  3  \n",
       "1                      0                      1  33                  3  \n",
       "2                      1                      1  37                  3  \n",
       "3                      1                      1  31                  3  \n",
       "4                      1                      1  34                  3  \n",
       "\n",
       "[5 rows x 30 columns]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 文本型变量转换"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.preprocessing import LabelEncoder\n",
    "le = LabelEncoder()\n",
    "feats_to_encode = ['City', 'Employer_Name', 'Salary_Account','Device_Type','Filled_Form','Gender','Mobile_Verified','Source','Var1','Var2','Var4']\n",
    "for col in feats_to_encode:\n",
    "    data[col] = le.fit_transform(data[col])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ID</th>\n",
       "      <th>Gender</th>\n",
       "      <th>City</th>\n",
       "      <th>Monthly_Income</th>\n",
       "      <th>Loan_Amount_Applied</th>\n",
       "      <th>Loan_Tenure_Applied</th>\n",
       "      <th>Existing_EMI</th>\n",
       "      <th>Employer_Name</th>\n",
       "      <th>Salary_Account</th>\n",
       "      <th>Mobile_Verified</th>\n",
       "      <th>...</th>\n",
       "      <th>Source</th>\n",
       "      <th>Var4</th>\n",
       "      <th>LoggedIn</th>\n",
       "      <th>Disbursed</th>\n",
       "      <th>source</th>\n",
       "      <th>EMI_Loan_Submitted_Missing</th>\n",
       "      <th>Interest_Rate_Missing</th>\n",
       "      <th>Processing_Fee_Missing</th>\n",
       "      <th>Age</th>\n",
       "      <th>Lead_Creation_Year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>ID000002C20</td>\n",
       "      <td>0</td>\n",
       "      <td>1577</td>\n",
       "      <td>20000</td>\n",
       "      <td>300000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>11484</td>\n",
       "      <td>16822</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>train</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>40</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ID000004E40</td>\n",
       "      <td>1</td>\n",
       "      <td>1862</td>\n",
       "      <td>35000</td>\n",
       "      <td>200000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>50902</td>\n",
       "      <td>16824</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>train</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>33</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ID000007H20</td>\n",
       "      <td>1</td>\n",
       "      <td>1913</td>\n",
       "      <td>22500</td>\n",
       "      <td>600000.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2534</td>\n",
       "      <td>16846</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>20</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>train</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>37</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>ID000008I30</td>\n",
       "      <td>1</td>\n",
       "      <td>1991</td>\n",
       "      <td>35000</td>\n",
       "      <td>1000000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>7563</td>\n",
       "      <td>16846</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>20</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>train</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>31</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ID000009J40</td>\n",
       "      <td>1</td>\n",
       "      <td>1489</td>\n",
       "      <td>100000</td>\n",
       "      <td>500000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>25000.0</td>\n",
       "      <td>17825</td>\n",
       "      <td>16822</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>11</td>\n",
       "      <td>3</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>train</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>34</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 30 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            ID  Gender  City  Monthly_Income  Loan_Amount_Applied  \\\n",
       "0  ID000002C20       0  1577           20000             300000.0   \n",
       "1  ID000004E40       1  1862           35000             200000.0   \n",
       "2  ID000007H20       1  1913           22500             600000.0   \n",
       "3  ID000008I30       1  1991           35000            1000000.0   \n",
       "4  ID000009J40       1  1489          100000             500000.0   \n",
       "\n",
       "   Loan_Tenure_Applied  Existing_EMI  Employer_Name  Salary_Account  \\\n",
       "0                  5.0           0.0          11484           16822   \n",
       "1                  2.0           0.0          50902           16824   \n",
       "2                  4.0           0.0           2534           16846   \n",
       "3                  5.0           0.0           7563           16846   \n",
       "4                  2.0       25000.0          17825           16822   \n",
       "\n",
       "   Mobile_Verified         ...          Source  Var4  LoggedIn  Disbursed  \\\n",
       "0                0         ...               0     1       0.0        0.0   \n",
       "1                1         ...               0     3       0.0        0.0   \n",
       "2                1         ...              20     1       0.0        0.0   \n",
       "3                1         ...              20     3       0.0        0.0   \n",
       "4                1         ...              11     3       1.0        0.0   \n",
       "\n",
       "   source  EMI_Loan_Submitted_Missing  Interest_Rate_Missing  \\\n",
       "0   train                           1                      1   \n",
       "1   train                           0                      0   \n",
       "2   train                           1                      1   \n",
       "3   train                           1                      1   \n",
       "4   train                           1                      1   \n",
       "\n",
       "   Processing_Fee_Missing  Age  Lead_Creation_Year  \n",
       "0                       1   40                   3  \n",
       "1                       1   33                   3  \n",
       "2                       1   37                   3  \n",
       "3                       1   31                   3  \n",
       "4                       1   34                   3  \n",
       "\n",
       "[5 rows x 30 columns]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "FE_train=data.loc[data['source']=='train'].drop('source',axis=1)\n",
    "FE_test=data.loc[data['source']=='train'].drop('source',axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "FE_train.to_csv('FE_train.csv')\n",
    "FE_test.to_csv('FE_test.csv')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.15"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
